
#include "net.h"
using namespace WtfEngine;

void Party::BroadcastOnLan(tPort port) {
	if(mStatus == PARTY_IDLE) {
		UdpBroadcastSocket::tRef rSocket = new UdpBroadcastSocket(port);

		//
		// Once we send the broadcast, clients will try to connect to us via TCP (control socket).
		//

		rSocket->SendPacket(new Packet<PartyBroadcastMessage>(CreateBroadcastMessage()));
	} else {
		throw new std::logic_error("Party cannot broadcast - not idle");
	};
};

PartyBroadcastMessage Party::CreateBroadcastMessage() const {
	PartyBroadcastMessage msg;
				
	msg.uCurrentPartySize = mvPeerList.size();
	msg.uRequestedPartySize = muMaxSize;
	msg.uGameId = muGameId;
	msg.iGameType = miGameType;
	msg.wPort = PeerManager::GetInstance().getControlSocket()->getPort();

	return msg;
};
